package com.itheima.guozi;

public class Cooker implements Runnable {
    @Override
    public void run() {
        //摊煎饼
        //死循环
        while (true){
            //判断做够了吗
            synchronized (Desk.obj) {
                if(Desk.count>0){
                    //判断桌子上有没有
                    if(Desk.flag){
                        //有  等着
                        try {
                            Desk.obj.wait();
                        } catch (InterruptedException e) {
                            e.printStackTrace();
                        }
                    }else {
                        //没有  做一个煎饼 叫人吃
                        try {
                            Thread.sleep(2000);
                        } catch (InterruptedException e) {
                            e.printStackTrace();
                        }
                        System.out.println(Thread.currentThread().getName()+"摊了一个煎饼");
                        Desk.flag=true;
                        Desk.obj.notifyAll();
                    }

                }else {
                    System.out.println("今天已经没面了 下班");
                    break;
                }
            }


        }

    }
}
